package com.wl.common.security.auto;

import com.wl.common.security.bean.IgnoreUrlsProperties;
import com.wl.common.security.bean.JwtProperties;
import com.wl.common.security.config.WebMvcConfig;
import com.wl.common.security.interceptor.AuthorityInterceptor;
import com.wl.common.security.interceptor.HeaderInterceptor;
import com.wl.common.security.register.SecurityMetadataSource;
import com.wl.common.security.register.LoginUserRegistry;
import com.wl.common.security.register.LoginUserRegistryImpl;
import com.wl.common.security.utils.JwtTokenUtil;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author: wanglin
 * @date: 2024-03-08 周五
 * @Version: 1.0
 * @Description:
 */
@Configuration
@EnableConfigurationProperties({JwtProperties.class, IgnoreUrlsProperties.class})
public class SecurityAutoConfiguration {
    @Bean
    public JwtTokenUtil jwtTokenUtil() {
        return new JwtTokenUtil();
    }

    @Bean
    public WebMvcConfig webMvcConfig() {
        return new WebMvcConfig();
    }

    @Bean
    public HeaderInterceptor headerInterceptor() {
        return new HeaderInterceptor();
    }

    @Bean
    public AuthorityInterceptor authorityInterceptor() {
        return new AuthorityInterceptor();
    }

    @Bean
    public PasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public SecurityMetadataSource dynamicSecurityMetadataSource() {
        return new SecurityMetadataSource();
    }

    @Bean
    public LoginUserRegistry loginUserRegistry() {
        return new LoginUserRegistryImpl();
    }
}
